﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BeatingMole
{
    /// <summary>
    /// Nguyễn Đặng Anh Duy
    /// MSSV : 11100204
    /// Email : itc.anhduy@gmail.com
    /// <summary>
    class CBusAbout
    {
        #region "Variable"
        private bool _isEnableBusMenu;
        bool IsReady = false;
        private int index = 0;

        MouseState MouseCur;
        MouseState MousePre;

        /// <summary>
        /// Lớp thông tin About
        /// </summary>
        CInfoAbout InfoAbout;
        /// <summary>
        /// Đối tượng quản lý Resource
        /// </summary>
        ContentManager _Content;
        private Vector2 PosAbout;
        #endregion

        #region "Properties"
        public bool IsEnableBusMenu
        {
            set { _isEnableBusMenu = value; }
            get { return _isEnableBusMenu; }
        }
        #endregion

        #region "Constructor"
        /// <summary>
        /// Phương thức khởi tạo của BusAbout
        /// </summary>
        /// <param name="content"></param>
        public CBusAbout(ContentManager content)
        {
            _Content = content;
            InfoAbout = new CInfoAbout(_Content);
            PosAbout = new Vector2(800, 0);
        }
        #endregion

        #region "Method"
        /// <summary>
        /// Quản lý qua lại
        /// </summary>
        private void ManagerAbout()
        {
            if (IsEnableBusMenu == false)
            {
                PosAbout.X -= CGlobalVariable.SpeedTranslate;
                if (PosAbout.X <= 0)
                {
                    PosAbout.X = 0;
                    IsReady = true;
                }
            }
            else
            {
                PosAbout.X += CGlobalVariable.SpeedTranslate;
                if (PosAbout.X >= 800)
                {
                    PosAbout.X = 800;
                }
            }
        }
        public void Update(GameTime gameTime)
        {
            ManagerAbout();
            if (IsReady == true)
            {
                MouseCur = Mouse.GetState();
                if (MouseCur.LeftButton == ButtonState.Pressed && MousePre.LeftButton == ButtonState.Released)
                {
                    if (new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1).Intersects(InfoAbout.RecBtnPrevious))
                    {
                        index--;
                        if (index < 0)
                        {
                            index = 3;
                        }
                    }
                    if (new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1).Intersects(InfoAbout.RecBtnNext))
                    {
                        index++;
                        if (index > 3)
                        {
                            index = 0;
                        }
                    }
                    if (new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1).Intersects(InfoAbout.RecBtnBackMenu))
                    {
                        IsEnableBusMenu = true;
                        IsReady = false;
                        CGlobalVariable.IsEnableMenu = true;
                        CGlobalVariable.PosMenuBack = CGlobalVariable.PositionMenu.LeftBack;
                    }
                }
                MousePre = MouseCur;
            }
        }
        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(InfoAbout.BgAbout, PosAbout, Color.White);
            spriteBatch.Draw(InfoAbout.BgBlack, PosAbout, Color.Black * CGlobalVariable.Opacity);
            spriteBatch.Draw(InfoAbout.ListTexture2D[index], new Vector2(100 + PosAbout.X, 100), Color.White);
            spriteBatch.Draw(InfoAbout.BtnPrevious, new Vector2(30 + PosAbout.X, 240), Color.White);
            spriteBatch.Draw(InfoAbout.BtnNext, new Vector2(715 + PosAbout.X, 240), Color.White);
            spriteBatch.Draw(InfoAbout.BtnPrevious, new Vector2(720 + PosAbout.X, 20), Color.White);
        }
        #endregion
    }
}
